package collections.stack;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.Stack;

public class StackDemo {

  public static void main(String[] args) {

    int[] input = {
            1, 2, 3, 4, 5
    };
    int[] output = {
            4, 2, 3, 5, 1
    };
    Stack<Integer> stack = new Stack<Integer>();

    int outputIndex = 0;

    for (int i = 0; i < input.length; i++) {

      stack.add(input[i]);
      System.out.println(i);
      //开始移除
      while (!stack.empty() && stack.peek() == output[outputIndex]) {
        stack.pop();
        outputIndex++;
      }

    }
//    System.out.println(stack.empty());
    System.out.println(stack.size());

  }


}
